<script>
	export default {
		globalData: {
			hostUrl: 'https://sttxsc.shirongtong.com', //正式地址
			// hostUrl: 'https://mall.supply.sxruanjian.cn', //测试地址
			statusBarHeight: 0,
			headAllHeight: 0,
			windowHeight: 0,
			windowWidth: 0,
			screenHeight: 0,
			currentVersion: '',
			albumAuthorization: '0',
			safeAreaBottom: 0,
			shareUid:0,
			isClose:0,
		},
		onLaunch: function() {
			console.log('App Launch')
			const that = this,
				systemInfo = uni.getSystemInfoSync();
			console.log('systemInfo', systemInfo)
			that.globalData.statusBarHeight = systemInfo.statusBarHeight;
			that.globalData.platform = systemInfo.platform;
			that.globalData.headAllHeight = that.globalData.statusBarHeight + 44;
			that.globalData.windowHeight = systemInfo.windowHeight;
			that.globalData.windowWidth = systemInfo.windowWidth;
			that.globalData.screenHeight = systemInfo.screenHeight;
			/* 小程序检测更新 */
			if (this.getPlatform() == 'mp') {
				this.updateMpWx();
				that.globalData.safeAreaBottom = systemInfo.safeAreaInsets.bottom;
			} else {
				that.globalData.safeAreaBottom = 54;
			}
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
			this.globalData.isClose = 0;
		},
		methods: {
			/* 检测小程序更新 */
			updateMpWx() {
				if (wx.canIUse('getUpdateManager')) {
					const updateManager = wx.getUpdateManager();
					updateManager.onCheckForUpdate(function(res) {
						console.log('res 小程序版本更新提示', res)
						// 请求完新版本信息的回调
						if (res.hasUpdate) {
							updateManager.onUpdateReady(function() {
								uni.showModal({
									confirmColor: "#5DC751",
									confirmText: '立即重启',
									title: '版本更新',
									showCancel: false,
									content: '新版本已经上线啦~，为了获得更好的体验，建议立即重启',
									success: function(res) {
										if (res.confirm) {
											// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
											updateManager.applyUpdate()
										}
									}
								})
							});
							updateManager.onUpdateFailed(function() {
								// 新的版本下载失败
								uni.showToast({
									title: '新版本更新失败，为了获得更好的体验，请您删除当前小程序，重新搜索打开',
									icon: 'none',
									mask: true,
								})
							});
						}
					});
				}
			},
			/* 公共接口请求 */
			globalRequest(param) {
				var token;
				token = uni.getStorageSync('TOKEN') ? uni.getStorageSync('TOKEN') : "";
				let that = this;
				return new Promise((resolve, reject) => {
					uni.request({
						url: `${this.globalData.hostUrl}/${param.api}`,
						method: param.method || "GET",
						timeout: 10000,
						dataType: 'json',
						header: {
							'Authorization': token
						},
						data: param.data,
						success(res) {
							uni.hideLoading()
							if (res.data.code == 101) {
								uni.removeStorageSync('TOKEN');
								uni.removeStorageSync('IS-MP-CLOSE');
							}else if(res.data.code == 10001){
								uni.showModal({
									title: '提示',
									content: res.data.msg,
									confirmColor: '#5DC751',
									showCancel:false,
									success(res) {
										console.log('res', res)
										if (res.confirm) {
											that.getCustomer()
										}
									}
								})
							}
							resolve(res.data)
						},
						fail(err) {
							uni.hideLoading();
							uni.showToast({
								title: '网络不给力，请稍候再试！',
								icon: 'none',
								mask: true,
							})
							reject(err)
						}
					})
				})
			},
			getCustomer() {
				let that = this;
				that.globalRequest({
					api: that.getApi().user.customer,
				}).then(res => {
					if (res.code == 0) {
						wx.openCustomerServiceChat({
							extInfo: {
								url: res.data.link_url
							},
							corpId: 'wwa5777f4dca0241d0', // 替换为你的企业ID
							success(res) {
								console.log('成功打开客服聊天界面');
							},
							fail(err) {
								console.log('打开客服聊天界面失败', err);
							}
						});
					}
				})
			},
			/* 所有Api接口 */
			getApi() {
				const apiUrl = {
					loginApi: {
						bindPhone:'api/bindPhone',
						login:'api/login',
						checkUserBindMobile:'api/checkUserBindMobile',
						saveUserData:'api/saveUserData'
					},
					baseApi: {
						upload: 'api/uploadFile',
						deleteFile: 'api/deleteFile',
						companyData: 'api/getCompanyData',
						globalCompanyId: 'api/globalCompanyId',
						protocol: 'api/protocol',
						kefu: 'api/kefu',
					},
					home: {
						indexHeader: 'api/indexHeader',
						recommand: 'api/indexMiddle',
						detailSlider: 'api/detailSlider',
						randomPoster: 'api/posterRandom',
						getNewGift:'api/getNewGift'
					},
					goods: {
						goodsDetail: 'api/goodsDetail',
						goodsShareImg:'api/goodsShareImg',
						saveUserCollect: 'api/saveUserCollect',
						categoryList: 'api/categoryList',
						categoryDetail: 'api/categoryDetail',
						goodList: 'api/goodList',
						recommendList: 'api/recommendList',
						addCart: 'api/addCart',
						cartList: 'api/cartList',
						cartTotal: 'api/getCartTotal',
						cartTotalPrice: 'api/getCartTotalPrice',
						editCart: 'api/editCart',
						clearCart: 'api/clearCart',
						cartCheck: 'api/cartCheck',
						goodsComment:'api/goodsComment'
					},
					order: {
						preOrder: 'api/order',
						buyNow: 'api/buyNow',
						orderSubmit: 'api/submit',
						orderDetail: 'api/orderDetail',
						changeAddress: 'api/changeAddress',
						orderList: 'api/orderList',
						createOrder: 'api/createOrder',
						orderCancel: 'api/orderCancle',
						receipt:'api/receipt',
						supplyOrderDetail: 'api/supplyOrderDetail',
						againOrder:'api/againOrder',
						Logistics:'api/Logistics',
						comment:'api/comment',
						getOrderItem:'api/getOrderItem',
						refundApply:'api/refundApply',
						refundDetail:'api/refundDetail',
						refundDelivery:'api/refundDelivery',
						deliveryCompany:'api/deliveryCompany',
						refundList:'api/refundList',
						refundCancle:'api/refundCancle',
						showOrderNums:'api/showOrderNums'
					},
					user: {
						getUserInfo: 'api/getLoginUser',
						saveAuthCompany: 'api/authCompany',
						addressList: 'api/addrList',
						saveAddress: 'api/saveAddress',
						detailAddr: 'api/detailAddr',
						setDefaultAddr: 'api/setDefaultAddr',
						deleteAddr: 'api/deleteAddr',
						userCollectList: 'api/userCollectList',
						batchCancelUserCollect: 'api/batchCancelUserCollect',
						batchCancelUserFoot: 'api/batchCancelUserFoot',
						userFootList: 'api/userFootList',
						findGoods: 'api/findGoods',
						historyFindGoods: 'api/historyFindGoods',
						getRegionList: 'api/getRegionList',
						logout: 'api/logout',
						userBillList: 'api/userBillList',
						getCompanyAccount: 'api/getCompanyAccount',
						userBillRecordList: 'api/userBillRecordList',
						customer: 'api/customer',
						finaceSetting:'api/finaceSetting'
					},
					coupon:{
						couponList:'api/couponList',
						userSaveCoupon:'api/userSaveCoupon',
						userCouponList:'api/userCouponList'
					},
					promotion:{
						shareOpen:'api/shareOpen',
						applyShare:'api/applyShare',
						shareCenter:'api/shareCenter',
						teamList:'api/teamList',
						commssionList:'api/commssionList',
						saveUserAccount:'api/saveUserAccount',
						getUserAccount:'api/getUserAccount',
						cash:'api/cash',
						cashInfo:'api/cashInfo',
						cashList:'api/cashList',
						userShareImg:'api/userShareImg',
						shareAgree:'api/shareAgree'
					}
				}
				return apiUrl
			},
			/* 判断运行环境 */
			getPlatform() {
				let platform = '';
				//#ifdef H5
				platform = 'h5'
				//#endif
				//#ifdef APP-PLUS
				platform = 'AppPlus';
				//#endif
				//#ifdef MP-WEIXIN
				platform = 'mp';
				//#endif
				return platform
			},

		}
	}
</script>

<style lang="scss">
	@import '@/static/css/animate.css';

	/*每个页面公共css */
	html,
	body {
		width: 100%;
		height: 100%;
		background: $supplier-page-color;
		color: $supplier-font-color;
		font-size: 28rpx;
	}

	@font-face {
		font-family: 'YouSheBiaoTiHei';
		src: url(https://front.sxruanjian.cn/ttf/YouSheBiaoTiHei.ttf) format('truetype');
	}
	@font-face {
		font-family: 'DIN-BOLD';
		src: url(https://front.sxruanjian.cn/ttf/DIN-BOLD.TTF) format('truetype');
	}

	@font-face {
		font-family: 'DIN-REGULAR';
		src: url(https://front.sxruanjian.cn/ttf/DIN-REGULAR.OTF) format('truetype');
	}

	::-webkit-scrollbar {
		display: none;
		width: 0 !important;
		height: 0 !important;
		-webkit-appearance: none;
		background: transparent;
	}

	uni-button {
		position: relative;
		display: block;
		margin-left: inherit;
		margin-right: inherit;
		padding-left: 0;
		padding-right: 0;
		box-sizing: border-box;
		font-size: inherit;
		text-align: inherit;
		text-decoration: none;
		line-height: inherit;
		border-radius: inherit;
		-webkit-tap-highlight-color: inherit;
		overflow: hidden;
		color: #000;
		background-color: inherit;
		cursor: pointer;
	}

	uni-button:after {
		content: "";
		width: 0;
		height: 0;
		position: absolute;
		top: 0;
		left: 0;
		border: inherit;
		box-sizing: border-box;
		border-radius: inherit;
		background: transparent;
		color: #fff
	}

	uni-button[disabled]:not([type]),
	uni-button[disabled][type=default] {
		background-color: rgba(93, 199, 81, 1) !important;
		color: rgba(255, 255, 255, 0.8);
		opacity: 0.6;
	}

	button {
		-webkit-tap-highlight-color: transparent;
		background-color: inherit;
		border-radius: inherit;
		box-sizing: border-box;
		color: inherit;
		cursor: pointer;
		display: block;
		font-size: inherit;
		line-height: inherit;
		margin-left: auto;
		margin-right: auto;
		overflow: hidden;
		padding-left: 0;
		padding-right: 0;
		position: relative;
		text-align: center;
		text-decoration: none;
	}

	button[disabled]:not([type]) {
		background-color: rgba(93, 199, 81, 1) !important;
		color: rgba(255, 255, 255, 0.8);
		opacity: 0.6;
	}

	button::after {
		border: 0;
	}

	.line-center {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.line-v-center {
		display: flex;
		align-items: center;
	}

	.pl {
		font-size: 28rpx;
		color: #9B9B9B;
	}

	.linear-goods-list-bg {
		width: 100%;
		height: 344rpx;
		position: absolute;
		left: 0;
		top: 0;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.ellipsis {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.line-ellipsis {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		overflow: hidden;
		text-overflow: ellipsis;
	}
	.modal-show {
		opacity: 1;
		visibility: visible;
	}
</style>